<?php
namespace app\manage\controller;
use app\model\AdminModel;
use app\model\AdvertisementModel;
use app\model\AuthGroupModel;
use app\model\MessageModel;
use app\model\PilotListModel;
use app\model\PilotNavModel;
use app\model\SystemModel;
use think\exception\ValidateException;
use think\facade\Db;
use support\Request;
use support\View;
use think\Validate;
/**
 * 控制器基础类
 */
abstract class Base
{
    // 初始化
    public function __construct()
    {
        $message=MessageModel::where('isopen','0')->count();
        View::assign('message', $message);
        //获取导航
        $pilot_nav=PilotNavModel::where('isopen',1)->order('sort asc')->select()->toArray();
        foreach ($pilot_nav as $k=>$v){
            if($v['id']==2 and session('uid')!=1){
                unset($pilot_nav[$k]);
            }
        }
        View::assign('pilot_nav', $pilot_nav);
        $user=AdminModel::where('id',session('uid'))->find();
        $pilot_list=[];
        if($user){
            if(session('uid')!=1 and $user['role']!=1){
                $idss=AuthGroupModel::where('id',$user['role'])->value('rules');
                $idss=explode(",", $idss);
                $idss[]=24;
                foreach ($pilot_nav as $k=>$v){
                    $arr= PilotListModel::where('fid',0)->where('pn_id',$v['id'])->where('isopen',1)->order('sort asc')->select()->toArray();
                    foreach ($arr as $k1=>$v1){
                        $zi=PilotListModel::where('id','in',$idss)->where('fid',$v1['id'])->where('isopen',1)->order('sort asc')->select()->toArray();
                        if($zi){
                            $arr[$k1]['zi']=$zi;
                        }
                        if(!$zi and !in_array($v1['id'],$idss)) {
                            unset($arr[$k1]);
                        }
                    }
                    $pilot_list[]=$arr;
                }
            }else{
                //侧边导航
                foreach ($pilot_nav as $k=>$v){
                    $arr=PilotListModel::where('fid',0)->where('pn_id',$v['id'])->where('isopen',1)->order('sort asc')->select()->toArray();
                    foreach ($arr as $k1=>$v1){
                        $arr[$k1]['zi']=PilotListModel::where('fid',$v1['id'])->where('isopen',1)->order('sort asc')->select();
                    }
                    $pilot_list[]=$arr;
                }
            }
        }
        View::assign('pilot_list', $pilot_list);
        View::assign('system', SystemModel::column('value','enname'));
        View::assign('is_empower', true);
    }



    /**
     * 验证数据
     * @access protected
     * @param  array        $data     数据
     * @param  string|array $validate 验证器名或者验证规则数组
     * @param  array        $message  提示信息
     * @param  bool         $batch    是否批量验证
     * @return array|string|true
     * @throws ValidateException
     */
    protected function validate(array $data, $validate, array $message = [], bool $batch = false)
    {

    }

}
